#include <any>
#include <iostream>

struct Base {
};

struct Derived1 : public Base {
    int i;
};

struct Derived2 : public Base {
    double d;
};

void Print1(const std::any &any)
{
    const struct Derived1 *ptr = std::any_cast<struct Derived1>(&any);
    if (ptr) {
        printf("%d\n", ptr->i);
    }
}

void Print2(const std::any &any)
{
    const struct Derived2 *ptr = std::any_cast<struct Derived2>(&any);
    if (ptr) {
        printf("%lf\n", ptr->d);
    }
}

void Print(const Base &base)
{
    Print1(base);
    Print2(base);
}

int main()
{
    Derived1 d1;
    Derived2 d2;
    d1.i = 3;
    d2.d = 1.5;
    Print(d1);
    Print(d2);
    // cannot do this
    return 0;
}
